package com.xidian.GMS.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xidian.GMS.dto.Page;
import com.xidian.GMS.entity.Announcement;
import com.xidian.GMS.entity.EnterpriseInformation;
import com.xidian.GMS.mapper.EnterpriseInformationMapper;
import com.xidian.GMS.service.EnterpriseInfoService;
@Service
public class EnterpriseInfoServiceImpl implements EnterpriseInfoService {
	@Autowired
	private EnterpriseInformationMapper enterpriseInfomapper;
	

	@Override
	public EnterpriseInformation insert(EnterpriseInformation enterpriseinfo) {
		// TODO Auto-generated method stub
		System.out.println(enterpriseinfo.getContacts());
		System.out.println(enterpriseinfo.getEnterpriseEmail());
		
		int rows=enterpriseInfomapper.insert(enterpriseinfo);
		if(rows==0||enterpriseinfo==null){
			throw new RuntimeException("错误");
		}
		return enterpriseinfo;
	}

	@Override
	public boolean delete(int enterpriseid) {
		// TODO Auto-generated method stub
		System.out.println(enterpriseid);
		int x = enterpriseInfomapper.deleteByPrimaryKey(enterpriseid);
		System.out.println("4313");
		if(x==1){
			return true;
		}
		    return false;

	}

	@Override
	public boolean update(EnterpriseInformation enterpriseinfo) {
		// TODO Auto-generated method stub
		EnterpriseInformation enterpriseinfo2=enterpriseInfomapper.selectByPrimaryKey(enterpriseinfo.getEnterpriseid());
		
		enterpriseinfo2.setEnterpriseName(enterpriseinfo.getEnterpriseName());
		enterpriseinfo2.setEnterpriseLocation(enterpriseinfo.getEnterpriseLocation());
		enterpriseinfo2.setSalary(enterpriseinfo.getSalary());
		enterpriseinfo2.setEnterpriseTelephone(enterpriseinfo.getEnterpriseTelephone());
		enterpriseinfo2.setProfession(enterpriseinfo.getProfession());
		enterpriseinfo2.setContacts(enterpriseinfo.getContacts());
		
		int temp=enterpriseInfomapper.updateByPrimaryKey(enterpriseinfo2);
		if(temp==1){
			return true;
		}
		   return false;
     
	}
	@Override
	public Page getEnterpriseInformation(int cur) {
		Page page = new Page(cur);
		
		int count = enterpriseInfomapper.count();
		
		List<EnterpriseInformation> accounts = enterpriseInfomapper.findAll(page.getOffset(), page.getSize());
		
		page.setCount(count);
		page.setList(accounts);
		
		return page;
	}
	

}
